package cate.game.pvp.gradepvp;

import cate.game.GameBody;
import cate.game.db.facade.KvLoader;
import cate.game.db.mongo.kv.KvMongo;
import cate.game.framework.ModuleMan;
import cate.game.play.part.PlaySide;
import cate.game.pvp.gradepvp.dto.GradePvpPlayerData;
import cate.game.role.RoleSimpleBase;
import cate.game.role.pvp.gradepvp.GradePvpRecord;

import java.util.List;

public class GradePvpManager extends ModuleMan {
    public GradePvpStatus status;
    public GradePvpMsgManager msg = new GradePvpMsgManager();

    @Override
    public void initDependent() throws Exception {
        msg.initDependent();
        status = new KvLoader<>(game, GradePvpStatus.class, KvMongo.KEY_GRADE_PVP).getBySrvId();
        status.initialize(game);
        GradePvpPeriod.initialize();
    }

    @Override
    public void initIndependent(GameBody game) throws Exception {
        super.initIndependent(game);
        msg.initIndependent(game);
    }

    @Override
    public void shutdown() {
        game.db.kv.save(status);
    }

    public void tick() {
        status.tick();
    }

    public void fightOver(PlaySide a, int star, int score, GradePvpRecord record) {
        msg.fightOver(a, star, score, record);
    }

    public GradePvpPlayerData match(String playerUid, int star) {
        return msg.match(playerUid, star);
    }

    public List<GradePvpRecord> loadNewBeeRecords() {
        return msg.loadNewBeeRecords();
    }

    public List<RoleSimpleBase> loadSixGod(int season) {
        return msg.loadSixGods(season);
    }

    public long getSeasonStartTime() {
        return status.seasonStartTime();
    }

    public int getRank(String roleUid) {
        return msg.loadRank(roleUid);
    }
}
